  /**
   * 常见问题
   */
  const faqTable = async (flow1, flow2) => {
    const table = new UITable();
    table.showSeparators = true;
    try {
      let faqData = new Request(
        'https://gitee.com/script_djg/scriptable/raw/master/Script/faq.json',
      );
      faqData = await faqData.loadJSON();
      for (let i = 0; i < faqData.data.length; i++) {
        let header = new UITableRow();
        header.backgroundColor = Color.dynamic(
          new Color('F5F5F5'),
          new Color('000000'),
        );
        if(faqData.data[i].name){
          let heading = header.addText(faqData.data[i].name);
          heading.titleFont = Font.mediumSystemFont(17);
          heading.centerAligned();
          table.addRow(header);
        }
        faqData.data[i].item.forEach((faq) => {
          let row = new UITableRow();
          row.height = parseFloat(faq['height']);
          let answer = faq['answer'];
          if(answer.indexOf('/a/') != -1) {
            answer = answer.replace('/a/', conver(flow1)).replace('/b/', conver(flow2));
          }
          let rowtext = row.addText(faq['question'], answer);
          rowtext.titleFont = Font.mediumSystemFont(16);
          rowtext.titleColor = i == 0 ? Color.red() : Color.blue();
          rowtext.subtitleFont = Font.systemFont(14);
          rowtext.subtitleColor = Color.dynamic(
            new Color('000000', 0.7),
            new Color('ffffff', 0.7),
          );
          if(faq['url']){
            row.onSelect = async () => {
	  		  await Safari.openInApp(faq['url'])
			}
          }
          table.addRow(row);
        });
      }
      let info = new UITableRow();
      info.height = parseFloat(faqData.height);
      let desc = info.addText(faqData.update);
      desc.titleFont = Font.mediumSystemFont(14);
      desc.titleColor = new Color('000000', 0.4)
      table.addRow(info);
      await table.present();
    } catch (e) {
      await generateAlert("啊～哦～貌似又断网了", ['知道了']);
    }
  }
  
  const conver = (limit) => {
    limit = parseFloat(limit);
    var size = "";
    if(limit < 0.1 * 1024 ){
      size = limit.toFixed(2) + "KB";
    } else if(limit < 0.1 * 1024 * 1024 ){
      size = (limit / 1024).toFixed(2) + "MB";
    } else {
      size = (limit / (1024 * 1024)).toFixed(2) + "GB";
    }
    var sizestr = size + "";
    var len = sizestr.indexOf("\.");
    var dec = sizestr.substr(len + 1, 2);
    if(dec == "00"){//当小数点后为00时 去掉小数部分
      return sizestr.substring(0,len) + sizestr.substr(len + 3,2);
    }
    return sizestr;
  }
  
  const generateAlert = async (message, options, title) => {
    let alert = new Alert();
    title && (alert.title = title);
    alert.message = title ? '\n' + message : message;
    if(options) {
      for (const option of options) {
        alert.addAction(option);
      }
    }
    return await alert.presentAlert();
  }
  
  module.exports = faqTable;